package sample;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;

import java.util.ArrayList;


public class ScreenSpilt extends Button {
    private final String root = "file:" + CantSee.root;
    private final String root2 = CantSee.root;
    public ImageView imageView;
    public static ScreenSpilt settingIt = null;
    public boolean selected;
    public boolean setting;
    public ScreenSpilt(String name){
        double height = 100;
        double width = height * 1.5;
        selected = false;
        setting = false;
        Image image = new Image(root + name + ".png");
        imageView = new ImageView(image);
        imageView.setFitWidth(width);
        imageView.setFitHeight(height);
        this.setId(name);
        this.setGraphic(imageView);
        ScreenSpilt scsp = this;
        this.setOnMouseEntered(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent mouseEvent) {
                if(!selected && !setting) {
                    scsp.setStyle("-fx-border-color: rgba(28, 134, 238,.9);\n" +
                            "    -fx-border-width: 1;\n" +
                            "    -fx-background-color: rgba(99, 184 ,255,.9);");
                }
            }
        });
        this.setOnMouseExited(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent mouseEvent) {
                if(setting){
                }else if(selected){
                }else{
                    scsp.setStyle("-fx-background-color: rgba(176 ,226, 255,.8);" +
                            "    -fx-opacity: 0.8;"+"-fx-background-radius: 10;" +
                            "    -fx-border-radius: 10;" +
                            "    -fx-border-width: 1;");
                }
            }
        });
        this.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent actionEvent) {
                switch (name){
                    case "spiltScrean_cross":
                    case "spiltScrean_half1":
                    case "spiltScrean_half2":
                    case "spiltScrean_three1":
                    case "spiltScrean_three2":
                    case "spiltScrean_three3":
                    case "spiltScrean_twoSpilt":
                    case "spiltScrean_threeSpiltDown":
                    case "spiltScrean_threeSpiltUp":
                    case "spiltScrean_twoSpiltRight":
                        break;
                    default:
                        selected = !selected;
                        if(selected&&setting){
                            scsp.setStyle("-fx-background-color: linear-gradient(to right, #ef651e, #e49a1e, #d2c71e, #b6f11f)");
                        }else if(selected){
                            scsp.setStyle("-fx-background-color: rgb(106,255,169,255)");
                            System.out.println("show");
                        }else if(setting){
                            scsp.setStyle("-fx-background-color: rgb(250,170,71)");
                        }else{
                            scsp.setStyle("-fx-background-color: rgba(176 ,226, 255,.8);" +
                                    "    -fx-opacity: 0.8;"+"-fx-background-radius: 10;" +
                                    "    -fx-border-radius: 10;" +
                                    "    -fx-border-width: 1;");
                            System.out.println("hide");
                        }
                }
            }
        });
    }
    private void clearALlFrame(){
        ArrayList<AppFrame> frameList = CantSee.frameList;
        for(int i = 0; i < frameList.size();i ++){
            frameList.get(i).rectangle.setVisible(false);
        }
        frameList.clear();
        CantSee.setChooseFrame(null);
    }


}
